#include "NetcdfDimensionData.h"

namespace OCPP
{
	NetcdfDimensionData::NetcdfDimensionData(int index)
		:dimensionIndex(index)
	{

	}

	void NetcdfDimensionData::read(GridVariablePtr variable, String alias, const VolumeOptions& options)
	{
		minValue = NC_MAX_FLOAT;
		maxValue = NC_MIN_FLOAT;

		_variable = variable;
		units = variable->getUnitsString();

		data = variable->readFloat();
		size = data.size();
		for (const auto& value : data)
		{
			minValue = std::min(minValue, value);
			maxValue = std::max(maxValue, value);
		}
	}

	void NetcdfDimensionData::read(GridVariablePtr variable, const VolumeOptions& options)
	{
		read(variable, "", options);
	}

	String NetcdfDimensionData::getLevelString(int i)
	{
		if (units == "m" || units == "km")
		{
			return str_format("%d", (int)data[i]) + units;
		}
		else if (units == "Pa" || units == "hPa")
		{
			return str_format("%d", (int)data[i]) + units;
		}
		return "";
	}

}